<template>
    <div class="app-container">
        <el-card class="filter-container" shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
        <el-button
          style="float:right"
          type="primary"
          @click="handleSearchList()"
          size="small">
          查询搜索
        </el-button>
        <el-button
          style="float:right;margin-right: 15px"
          @click="handleResetSearch()"
          size="small">重置</el-button>
      </div>
      <div style="margin-top: 45px">
        <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
          <!-- <el-form-item label="预约人">
            <el-input class="input-width" placeholder="预约人姓名/手机号码"></el-input>
          </el-form-item> -->
          <el-form-item label="预约时间：">
            <el-date-picker v-model="listQuery.endTime" class="input-width"  value-format="yyyy-MM-dd"
              type="date"
              placeholder="请选择时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="预约状态：">
             <el-select v-model="listQuery.status"  class="input-width" placeholder="全部" clearable>
              <el-option v-for="item in typeOptions"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
    </el-card>
    <div class="table-container">
      <el-table ref="orderTable"
                :data="list"
                style="width: 100%;"
                @selection-change="handleSelectionChange"
                v-loading="listLoading" border>
        <el-table-column type="selection" width="60" align="center"></el-table-column>
        <el-table-column label="编号" width="80" align="center">
          <template slot-scope="scope">{{scope.row.id}}</template>
        </el-table-column>
        <el-table-column label="预约时间" width="180" align="center">
          <template slot-scope="scope">{{scope.row.startTime}} - {{scope.row.endTime}}</template>
        </el-table-column>
        <el-table-column label="卡座简称" width="80" align="center">
          <template slot-scope="scope">{{scope.row.capacity}}</template>
        </el-table-column>
        <el-table-column label="卡座名称" width="120" align="center">
          <template slot-scope="scope">{{scope.row.seatName}}</template>
        </el-table-column>
        <el-table-column label="用户姓名" align="center">
          <template slot-scope="scope">{{scope.row.username }}</template>
        </el-table-column>
        <el-table-column label="用户手机号码" align="center">
          <template slot-scope="scope">{{scope.row.phone }}</template>
        </el-table-column>
        <el-table-column label="创建时间" width="180" align="center">
           <template slot-scope="scope">{{scope.row.reservationDate | formatCreateTime}}</template>
        </el-table-column>
        <el-table-column label="订单状态" width="120" align="center">
          <template slot-scope="scope">{{scope.row.status | formatStatus}}</template>
        </el-table-column>
        <el-table-column label="操作" width="260" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleCloseOrder(scope.$index, scope.row)"
              v-show="scope.row.status===0">关闭预约</el-button>
            <el-button
              size="mini"
              @click="handleDeliveryOrder(scope.$index, scope.row)"
              v-show="scope.row.status===1">已到店</el-button>
            <el-button
              size="mini"
              @click="handleViewLogistics(scope.$index, scope.row)"
              v-show="scope.row.status===2">已使用</el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDeleteOrder(scope.$index, scope.row)">删除预约</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize"
        :page-sizes="[5,10,15]"
        :total="total">
      </el-pagination>
    </div>
</div>
</template>
<script> 
 import {teaRecordList} from "@/api/records"
 import {formatDate} from '@/utils/date';
   const defaultListQuery = {
      pageNum: 1,
      pageSize: 5,
      status: null,
      endTime:null
    };
    //0：禁用 1：可使用 2：已使用 3：已过期
    const typeOptions = [
      {
      label: '全部',
      value: null
      },
     {
      label: '已禁用',
      value: '1'
     },
     {
      label: '可使用',
      value: '2'
     },
     {
      label: '已过期',
      value: '3'
     }
  ];
 export default { 
  name: 'appointmentRecord',
  data(){
    return {
      listQuery: Object.assign({}, defaultListQuery),
      list:null,
      listLoading:false,
      total: null,
      multipleSelection: [],
      typeOptions
  }
  },
  created() {
     this.getList();
  },
  methods:{
    handleCloseOrder(index, row){

    }, 
    handleDeliveryOrder(index, row){

    },
    handleViewLogistics(index, row){

    },
    handleDeleteOrder(index, row){ 
    },
     getList(){
      this.listLoading = true;
      teaRecordList(this.listQuery).then(response=>{
      this.list = response.data.list;
      this.total = response.data.total;
    }).catch(error => {
      console.error('获取预约记录失败:', error);
    }).finally(() => {
      this.listLoading = false;
    });
    },
    handleSearchList() {
        this.listQuery.pageNum = 1;
        this.getList();
    },
    handleResetSearch() {
        this.listQuery = Object.assign({}, defaultListQuery);
        this.getList();
    } ,
    handleSelectionChange(val){
        this.multipleSelection = val;
      },
     handleSizeChange(val){
        this.listQuery.pageNum = 1;
        this.listQuery.pageSize = val;
        this.getList();
      },
      
      handleCurrentChange(val){
        this.listQuery.pageNum = val;
        this.getList();
      }
  },
  filters:{
     //0：禁用 1：可使用 2：已使用 3：已过期
    formatStatus(value) {
        if (value === 1) {
          return '可使用';
        } else if (value === 2) {
          return '已使用';
        } else if (value === 3) {
          return '已过期';
        } else {
          return '已禁用';
        }
      },
      formatCreateTime(time) {
        let date = new Date(time);
        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
      },
  }
 }
</script>